package com.rmuti.programming.testswt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class UITest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		shell.setLayout(layout);
		shell.setSize(385, 524);
		
		Label label = new Label(shell, SWT.PUSH);
		Image image = new Image(display, "icons/image/header.gif");
		label.setBackgroundImage(image);
		
		GridData gridData = new GridData(385, 55);
		label.setLayoutData(gridData);
		label.setText("ปฏิบัติการเขียนโปรแกรม");

		Table table = new Table(shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		GridData data = new GridData(350,360);
		table.setLayoutData(data);

		
		String[] titles = { "First Name", "Last Name", "Age" };
		for (int i = 0; i < titles.length; i++) {
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(titles[i]);
			table.getColumn(i).pack();
		}
		
		for (int i = 0 ; i<= 50 ; i++){
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText (0, "Person " +i);
			item.setText (1, "LastName " +i);
			item.setText (2, String.valueOf(i));
		}
		
		for (int i=0; i<titles.length; i++) {
			table.getColumn (i).pack ();
		}
		
		GridData buttomLayout = new GridData(385, 55);
		
		Label buttomLabel = new Label(shell, SWT.PUSH);
		buttomLabel.setBackgroundImage(image);
		buttomLabel.setLayoutData(buttomLayout);
		
//		Button but = new Button(buttomLabel,SWT.PUSH);
//		but.setLayoutData(buttomLayout);
		
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}
